package me.denley.preferencebinder.internal;

public enum WidgetBindingType {
    ASSIGN(
            null,
            "%s = %s",
            null,
            null
    ),
    ENABLED(
            PrefType.BOOLEAN,
            "%s.setEnabled(%s)",
            null,
            null
    ),
    SELECTED(
            PrefType.BOOLEAN,
            "%s.setSelected(%s)",
            null,
            null
    ),
    VISIBILITY(
            PrefType.BOOLEAN,
            "%s.setVisibility(%s ? ohos.agp.components.Component.VISIBLE : ohos.agp.components.Component.HIDE)",
            null,
            null
    ),
    CHECKED(
            PrefType.BOOLEAN,

            "%s.setChecked(%s)",

            "%s.setCheckedStateChangedListener(new ohos.agp.components.AbsButton.CheckedStateChangedListener() {" + System.lineSeparator() +
            "            @Override public void onCheckedChanged(final ohos.agp.components.AbsButton absButton, final boolean isChecked) {" + System.lineSeparator() +
            "                prefs.putBoolean(%s, isChecked).flush();" + System.lineSeparator() +
            "            }" + System.lineSeparator() +
            "        })",

            "%s.setCheckedStateChangedListener(null)"
    ),
    TEXT(
            PrefType.STRING,
            "%s.setText(%s)",
            null,
            null
    ),
    PROGRESS(
            PrefType.INTEGER,
            "%s.setProgressValue(%s)",
            null,
            null
    ),
    SLIDER_PROGRESS(
            PrefType.INTEGER,

            "%s.setProgressValue(%s)",

            "%s.setValueChangedListener(new ohos.agp.components.Slider.ValueChangedListener() {" + System.lineSeparator() +
                    "            @Override public void onProgressUpdated(final ohos.agp.components.Slider slider, final int progress, final boolean fromUser) {" + System.lineSeparator() +
                    "                prefs.putInt(%s, progress).flush();" + System.lineSeparator() +
                    "            }" + System.lineSeparator() +
                    "            @Override public void onTouchStart(final ohos.agp.components.Slider slider) { }" + System.lineSeparator() +
                    "            @Override public void onTouchEnd(final ohos.agp.components.Slider slider) { }" + System.lineSeparator() +
                    "        })",

            "%s.setValueChangedListener(null)"
    ),
    MAX_PROGRESS(
            PrefType.INTEGER,
            "%s.setMaxValue(%s)",
            null,
            null
    );

    public final PrefType prefType;
    public final String bindingCall;
    public final String listenerCall;
    public final String listenerUnbind;

    WidgetBindingType(PrefType prefType, String bindingCall, String listenerCall, String listenerUnbind) {
        this.prefType = prefType;
        this.bindingCall = bindingCall;
        this.listenerCall = listenerCall;
        this.listenerUnbind = listenerUnbind;
    }
}
